﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Editor.QuestionInterface
{
    public partial class QuestionPage : UserControl
    {
        private List<Panel> panels;
        /// <summary>
        /// HelperQuestions will be populated at the create new interactive page form! 
        /// </summary>
        private List<HelperQuestionUserControl> helperQuestions;
        /// <summary>
        /// NumberOfHintsLeft will be set where HelperQuestions are populated and will be NOHL = HQ.Count;
        /// </summary>
        private int numberOfHintsLeft;
        /// <summary>
        /// There will be more than one answer to a problem example: 3 3.0 3. 
        /// or sometimes (3, 4), [3, 4], {3, 4} or simply 3, 4 (seperate the value by , it is important!
        /// </summary>
        private List<string> acceptedAnswers;

        public string CorrectAnswerDescription { get; set; }
        public string IncorrectAnswerDescription { get; set; }

        public List<HelperQuestionUserControl> HelperQuestions
        {
            get
            {
                return helperQuestions;
            }
            set
            {
                helperQuestions.Clear();
                helperQuestions.AddRange(value);
                numberOfHintsLeft = value.Count;
                utilityButtonHint.Text = "İpucu (" + numberOfHintsLeft + ")";
            }
        }

        public string Answers
        {
            set
            {
                acceptedAnswers.Clear();
                acceptedAnswers.AddRange( value.Split(new string[] { "; " }, 
                    StringSplitOptions.RemoveEmptyEntries));
            }
        }

        public string MainQuestionText
        {
            set
            {
                transparentLabelMainQuestionText.Text = value;
            }
        }

        public string Subject
        {
            set
            {
                transparentLabelSubject.Text = value;
            }
        }

        public string Result
        {
            set
            {
                transparentLabelResult.Text = value;
            }
        }

        public string Format
        {
            set
            {
                transparentLabelFormat.Text = value;
            }
        }

        public string Description
        {
            set
            {
                transparentLabelDescription.Text = value;
            }
        }

        public QuestionPage()
        {
            InitializeComponent();
            acceptedAnswers = new List<string>();
            helperQuestions = new List<HelperQuestionUserControl>();
            panels = new List<Panel>();
            transparentLabelResult.Text = "";
            transparentLabelDescription.Text = "";
            panels.Add(panel1);
            panels.Add(panel2);
            panels.Add(panel3);
            panels.Add(panel4);
        }

        private void utilityButtonHint_Click(object sender, EventArgs e)
        {
            int index = helperQuestions.Count - numberOfHintsLeft;

            if (numberOfHintsLeft == 0)
            {
                if (utilityButtonHint.Text != "Göster")
                    return;
            }
            else if (numberOfHintsLeft < 0)
            {
                return;
            }
            else
            {
                if (numberOfHintsLeft == 1)
                {
                    utilityButtonHint.Text = "Göster";
                }
                else
                    utilityButtonHint.Text = "İpucu (" + (numberOfHintsLeft - 1) + ")";

                panels[index].Controls.Add(helperQuestions[index]);
                numberOfHintsLeft--;
            }
        }

        private void utilityButtonAnswer_Click(object sender, EventArgs e)
        {
            if (acceptedAnswers.Contains(textBoxAnswer.Text))
            {
                Result = "DOĞRU CEVAP. TEBRİKLER!";
                Description = CorrectAnswerDescription;
            }
            else
            {
                Result = "YANLIŞ CEVAP. TEKRAR DENEYİN.";
                Description = IncorrectAnswerDescription;
            }
        }
    }
}
